﻿@namespace MudBlazor

@inherits MudComponentBase

<MudElement HtmlTag="ul" Class="@Classname" Style="@Style" Tag="@Tag" UserAttributes="@UserAttributes">
    @if (ShowFirstButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@FirstIcon" Size="@Size" Variant="@Variant" Disabled="@(Selected == 1 || Disabled)" OnClick="@(() => OnClickControlButton(Page.First))"></MudIconButton>
        </li>
    }
    @if (ShowPreviousButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@BeforeIcon" Size="@Size" Variant="@Variant" Disabled="@(Selected == 1 || Disabled)" OnClick="@(() => OnClickControlButton(Page.Previous))"></MudIconButton>
        </li>
    }
    @foreach (var state in GeneratePagination())
    {
        var currentPage = state;
        if (currentPage == -1)
        {
            <li class="@ItemClassname">
                <MudText disabled="@Disabled">...</MudText>
            </li>
        }
        else if (currentPage == Selected)
        {
            <li class="@SelectedItemClassname">
                <MudButton Variant="@(Variant == Variant.Outlined ? Variant.Outlined : Variant.Filled)" Size="@Size" DisableRipple="true" Disabled="@Disabled" Color="@Color">@currentPage</MudButton>
            </li>
        }
        else {
            <li class="@ItemClassname">
                <MudButton OnClick="@(() => Selected = currentPage)" Variant="@Variant" Size="@Size" DisableRipple="true" Disabled="@Disabled">@currentPage</MudButton>
            </li>
        }
    }
    @if (ShowNextButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@NextIcon" Variant="@Variant" Size="@Size" Disabled="@(Selected == Count || Disabled)" OnClick="@(() => OnClickControlButton(Page.Next))"></MudIconButton>
        </li>
    }
    @if (ShowLastButton)
    {
        <li class="@ItemClassname">
            <MudIconButton Icon="@LastIcon" Variant="@Variant" Size="@Size" Disabled="@(Selected == Count || Disabled)" OnClick="@(() => OnClickControlButton(Page.Last))"></MudIconButton>
        </li>
    }
</MudElement>